package com.bailan.foreat.controller;


import com.bailan.foreat.entity.China;
import com.bailan.foreat.service.ChinaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ste
 * @since 2023-02-21 07:50:43
 */
@RestController
@RequestMapping("/china")
public class ChinaController {
    @Autowired
    ChinaService chinaService;


    /**
     * 如果查询不到该pid对应地区，则查询该id对应值
     * @param pid
     * @return
     */
    @RequestMapping("queryList")
    public List<China> queryList(Integer pid){
        //约定: pid为0时查询的是省份.

        List<China> result = chinaService.queryList(pid);

        if (result.size() <= 0){
            ArrayList<China> list = new ArrayList<>();
            list.add(chinaService.queryById(pid));
            return list;
        }
        return result;
    }

}

